﻿using System;
using System.Collections.Generic;
using System.Web;
using Demo.Model;
using Pampa.MVC.Fluent.Crud;

namespace Pampa.MVC.Models
{
    public class CustomerEditConfig : EntityConfig<Customer>
    {
        public override void Init()
        {
            var group = AddGroup().Id("Main").Title("Main Data").Columns(2);
            group.AddTextItem(c => c.LastName).Label("Last Name").LabelWidth(150).MaxLength(20).Required();
            group.AddTextItem(c => c.FirstName).Label("First Name").MaxLength(20).Required();
            group.AddTextItem(c => c.Email).Label("Email").MaxLength(20).Required().Email();
            group.AddDateDropDowns(c => c.BirthDate).Label("Birth Date").Required().YearFrom(1920).YearTo(2010);
            group.AddTextItem(c => c.Limit).Label("Limit").MaxLength(20).Required().Integer("Credit Limit must be a number between 0 and 1000.", 0, 1000);
            group.AddEntitySelector(c => c.Nationality).Label("Nationality").EmptyText("Seleccione...");

            group.AddEntityDropDown(c => c.Type).Label("Customer Type").LabelWidth(150).OrderBy(c => c.Description).EmptyText("Seleccione...").Where(t => !t.IsNew);

            group.AddEntityDropDown(c => c.Preferences).Label("Preferences").Multiple();
            group.AddEntitySelector(c => c.Hobbies).Label("Hobbies").Multiple();

            group.AddCheckBox(c => c.Active).Label("Active");
            group.AddTextItem(c => c.Observations).Label("Observations").Multiline(50);
            group.AddViewItem(c => c.User).Label("User");
            group.AddViewItem(c => c.LastModification).Label("Last Modification");

            var group2 = AddGroup().Id("Address").Title("Address").Columns(2);
            group2.AddEntityDropDown(c => c.Address.City.State).Label("State").Required();
            group2.AddEntitySelector(c => c.Address.City).Label("City").Parent(c => c.Address.City.State, c => c.State.ID).EmptyText("Seleccione...");
            group2.AddTextItem(c => c.Address.Street).Label("Street").MaxLength(20).Required();
            group2.AddTextItem(c => c.Address.Number).Label("Number").MaxLength(20).Required().Integer();

            var group3 = AddListGroup(c => c.Phones).Title("Phones");
            group3.AddDropDown(c => c.Type).Label("Type").RadioButtons().AddItem("H", "Home").AddItem("W", "Work");
            group3.AddTextItem(c => c.Number).Label("Number").MaxLength(20).Required();
        }
    }
}
  